package no.sachmuld.methodcombination.examples.annotation.clossimplestyle.equalshashcode.v2;

import no.sachmuld.methodcombination.api.MethodCombinationSupport;
import no.sachmuld.methodcombination.api.annotation.And;
import no.sachmuld.methodcombination.api.annotation.MethodCombinationException;
import no.sachmuld.methodcombination.api.annotation.UsesMethodCombination;

import java.util.Arrays;
import java.util.List;

/**
 *
 */
@UsesMethodCombination(PointBehaviour.class)
public class Point2D extends MethodCombinationSupport<PointBehaviour> {

    private int x;
    private int y;

    public Point2D(final int x, final int y) {

        this.x = x;
        this.y = y;

        with(new PointBehaviour() {

            @Override
            public List<Integer> hashCodes() {
                return Arrays.asList(x, y);
            }

            @Override
            public boolean equals(Object obj) {
                if (Point2D.this == obj) return true;
                if (obj == null || Point2D.this.getClass() != obj.getClass()) return false;

                Point2D other = (Point2D) obj;

                if (x != other.x) return false;
                if (y != other.y) return false;

                return true;

            }

        });

    }

    @Override
    @HashCode
    public final int hashCode() {
        throw new MethodCombinationException();
    }

    @Override
    @And
    public final boolean equals(Object obj) {
        throw new MethodCombinationException();
    }

}
